/*
 * frame_buffer.c
 *
 *  Created on: 2011/06/17
 *      Author: AKS
 */

#include "core/include/aks_processor.h"
#include "core/include/process.h"
#include "core/include/types.h"
#include "core/include/aks_string.h"

#include "app/frame_buffer/include/frame_buffer.h"


BOOL init_frame_buffer(DWORD base_adr)
{
	WORD tick;

	EXTBUS_read(base_adr + 0x0fffff);
	tick = TIMER_systemTick();
    while( TIMER_systemTick() < (200 + tick) );
    EXTBUS_write ((base_adr + 0x0fffff), 0x00);


    EXTBUS_read(base_adr + 0x1fffff);
    tick = TIMER_systemTick();
    while( TIMER_systemTick() < (200 + tick) );
    EXTBUS_write ((base_adr + 0x1fffff), 0x01);

    return TRUE;
}


BOOL frame_buffer_switched(DWORD base_adr, BYTE index)
{
	DWORD baseAddress = (base_adr) | ((DWORD)index&0x01) << 20;

    return (index == EXTBUS_read(baseAddress + 0x0fffff)) ? 1 : 0;
}
